package org.example.spring.repository.service.impl;

import org.example.spring.repository.service.IDepartmentService;
import org.example.spring.repository.service.IManyThreadsTransactionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * LuoYu
 * 2022/12/19 11:14
 **/
@Service
public class SpringAsyncTransactionServiceImpl implements IManyThreadsTransactionService {

    @Resource
    private IDepartmentService departmentService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void exec() {
        departmentService.create("ssssss",false);
        int size = 5;
        for (int i=0;i<size;i++) {
            boolean hasThrow = i % 3 == 0;
            departmentService.asyncCreateRequired(String.valueOf(i),hasThrow);
        }

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
